<test>
  <sql>WITH EmployeeHierarchy AS
(
	-- Base case
	SELECT	EmployeeID
	FROM	Employees
	WHERE	ReportsTo IS NULL

	UNION ALL

	-- Recursive step
	SELECT	e.EmployeeId
	FROM	EmployeeHierarchy eh 
				INNER JOIN Employees e ON e.ReportsTo = eh.EmployeeID
	UNION ALL

	-- Recursive step
	SELECT	e.EmployeeId
	FROM	EmployeeHierarchy eh 
				INNER JOIN Employees e ON e.ReportsTo = eh.EmployeeID
	UNION ALL

	-- Recursive step
	SELECT	e.EmployeeId
	FROM	EmployeeHierarchy eh 
				INNER JOIN Employees e ON e.ReportsTo = eh.EmployeeID
)
SELECT	*
FROM	EmployeeHierarchy
ORDER	BY 1</sql>
  <expectedResults>
    <NewDataSet>
  <xs:schema id="NewDataSet" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
      <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
          <xs:element name="Table1">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="EmployeeID" type="xs:int" minOccurs="0" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:complexType>
    </xs:element>
  </xs:schema>
  <Table1>
    <EmployeeID>1</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>1</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>1</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>2</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>3</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>3</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>3</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>4</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>4</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>4</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>5</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>5</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>5</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>6</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>6</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>6</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>6</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>6</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>6</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>6</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>6</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>6</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>7</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>7</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>7</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>7</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>7</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>7</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>7</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>7</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>7</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>8</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>8</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>8</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>9</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>9</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>9</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>9</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>9</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>9</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>9</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>9</EmployeeID>
  </Table1>
  <Table1>
    <EmployeeID>9</EmployeeID>
  </Table1>
</NewDataSet>
  </expectedResults>
  <expectedPlan>
    <executionPlan>
      <element operator="Select">
        <properties>
          <property name="Output List.[0]" value="Union1014 AS EmployeeID" />
          <property name="Output List.[0].Column" value="Union1014" />
          <property name="Output List.[0].DataType" value="Int32" />
          <property name="Output List.[0].Output Name" value="EmployeeID" />
        </properties>
        <input>
          <element operator="Sort">
            <properties>
              <property name="Output List.[0]" value="Union1014" />
              <property name="Output List.[0].Column" value="Union1014" />
              <property name="Output List.[0].DataType" value="Int32" />
              <property name="Statistics.Open Count" value="1" />
              <property name="Statistics.Row Count" value="43" />
              <property name="Statistics.Average Row Count" value="43" />
              <property name="Logical Operator" value="Sort" />
              <property name="Order By.[0]" value="Union1014 ASC" />
              <property name="Order By.[0].Column" value="Union1014" />
              <property name="Order By.[0].DataType" value="Int32" />
              <property name="Order By.[0].Order" value="ASC" />
            </properties>
            <input>
              <element operator="IndexSpool">
                <properties>
                  <property name="Output List.[0]" value="Union1014" />
                  <property name="Output List.[0].Column" value="Union1014" />
                  <property name="Output List.[0].DataType" value="Int32" />
                  <property name="Statistics.Open Count" value="1" />
                  <property name="Statistics.Row Count" value="43" />
                  <property name="Statistics.Average Row Count" value="43" />
                  <property name="Logical Operator" value="Lazy Spool" />
                  <property name="With Stack" value="True" />
                </properties>
                <input>
                  <element operator="Concatenation">
                    <properties>
                      <property name="Output List.[0]" value="Union1013" />
                      <property name="Output List.[0].Column" value="Union1013" />
                      <property name="Output List.[0].DataType" value="Int32" />
                      <property name="Output List.[1]" value="Union1014" />
                      <property name="Output List.[1].Column" value="Union1014" />
                      <property name="Output List.[1].DataType" value="Int32" />
                      <property name="Statistics.Open Count" value="1" />
                      <property name="Statistics.Row Count" value="43" />
                      <property name="Statistics.Average Row Count" value="43" />
                      <property name="Defined Values.Union1013" value="Expr1002; Expr1005" />
                      <property name="Defined Values.Union1013.[0]" value="Expr1002" />
                      <property name="Defined Values.Union1013.[0].Column" value="Expr1002" />
                      <property name="Defined Values.Union1013.[0].DataType" value="Int32" />
                      <property name="Defined Values.Union1013.[1]" value="Expr1005" />
                      <property name="Defined Values.Union1013.[1].Column" value="Expr1005" />
                      <property name="Defined Values.Union1013.[1].DataType" value="Int32" />
                      <property name="Defined Values.Union1014" value="Employees.EmployeeID; Union1012" />
                      <property name="Defined Values.Union1014.[0]" value="Employees.EmployeeID" />
                      <property name="Defined Values.Union1014.[0].Table" value="Employees" />
                      <property name="Defined Values.Union1014.[0].Column" value="EmployeeID" />
                      <property name="Defined Values.Union1014.[0].DataType" value="Int32" />
                      <property name="Defined Values.Union1014.[1]" value="Union1012" />
                      <property name="Defined Values.Union1014.[1].Column" value="Union1012" />
                      <property name="Defined Values.Union1014.[1].DataType" value="Int32" />
                    </properties>
                    <input>
                      <element operator="ComputeScalar">
                        <properties>
                          <property name="Output List.[0]" value="Employees.EmployeeID" />
                          <property name="Output List.[0].Table" value="Employees" />
                          <property name="Output List.[0].Column" value="EmployeeID" />
                          <property name="Output List.[0].DataType" value="Int32" />
                          <property name="Output List.[1]" value="Expr1002" />
                          <property name="Output List.[1].Column" value="Expr1002" />
                          <property name="Output List.[1].DataType" value="Int32" />
                          <property name="Statistics.Open Count" value="1" />
                          <property name="Statistics.Row Count" value="1" />
                          <property name="Statistics.Average Row Count" value="1" />
                          <property name="Defined Values.[0]" value="Expr1002 = 0" />
                          <property name="Defined Values.[0].Target" value="Expr1002" />
                          <property name="Defined Values.[0].DataType" value="Int32" />
                          <property name="Defined Values.[0].Source" value="0" />
                        </properties>
                        <input>
                          <element operator="Filter">
                            <properties>
                              <property name="Output List.[0]" value="Employees.EmployeeID" />
                              <property name="Output List.[0].Table" value="Employees" />
                              <property name="Output List.[0].Column" value="EmployeeID" />
                              <property name="Output List.[0].DataType" value="Int32" />
                              <property name="Statistics.Open Count" value="1" />
                              <property name="Statistics.Row Count" value="1" />
                              <property name="Statistics.Average Row Count" value="1" />
                              <property name="Predicate" value="Employees.ReportsTo IS NULL" />
                            </properties>
                            <input>
                              <element operator="TableScan">
                                <properties>
                                  <property name="Table" value="Employees AS Employees" />
                                  <property name="Output List.[0]" value="Employees.EmployeeID" />
                                  <property name="Output List.[0].Table" value="Employees" />
                                  <property name="Output List.[0].Column" value="EmployeeID" />
                                  <property name="Output List.[0].DataType" value="Int32" />
                                  <property name="Output List.[1]" value="Employees.ReportsTo" />
                                  <property name="Output List.[1].Table" value="Employees" />
                                  <property name="Output List.[1].Column" value="ReportsTo" />
                                  <property name="Output List.[1].DataType" value="Int32" />
                                  <property name="Statistics.Open Count" value="1" />
                                  <property name="Statistics.Row Count" value="9" />
                                  <property name="Statistics.Average Row Count" value="9" />
                                </properties>
                                <input />
                              </element>
                            </input>
                          </element>
                        </input>
                      </element>
                      <element operator="Assert">
                        <properties>
                          <property name="Output List.[0]" value="Expr1005" />
                          <property name="Output List.[0].Column" value="Expr1005" />
                          <property name="Output List.[0].DataType" value="Int32" />
                          <property name="Output List.[1]" value="Union1012" />
                          <property name="Output List.[1].Column" value="Union1012" />
                          <property name="Output List.[1].DataType" value="Int32" />
                          <property name="Statistics.Open Count" value="1" />
                          <property name="Statistics.Row Count" value="42" />
                          <property name="Statistics.Average Row Count" value="42" />
                          <property name="Predicate" value="CASE WHEN Expr1005 &gt; 100 THEN 0 END" />
                        </properties>
                        <input>
                          <element operator="NestedLoops">
                            <properties>
                              <property name="Output List.[0]" value="Expr1005" />
                              <property name="Output List.[0].Column" value="Expr1005" />
                              <property name="Output List.[0].DataType" value="Int32" />
                              <property name="Output List.[1]" value="Union1012" />
                              <property name="Output List.[1].Column" value="Union1012" />
                              <property name="Output List.[1].DataType" value="Int32" />
                              <property name="Logical Operator" value="Inner Join" />
                              <property name="Statistics.Open Count" value="1" />
                              <property name="Statistics.Row Count" value="42" />
                              <property name="Statistics.Average Row Count" value="42" />
                              <property name="Outer References.[0]" value="Expr1004" />
                              <property name="Outer References.[0].Column" value="Expr1004" />
                              <property name="Outer References.[0].DataType" value="Int32" />
                            </properties>
                            <input>
                              <element operator="ComputeScalar">
                                <properties>
                                  <property name="Output List.[0]" value="Expr1004" />
                                  <property name="Output List.[0].Column" value="Expr1004" />
                                  <property name="Output List.[0].DataType" value="Int32" />
                                  <property name="Output List.[1]" value="Expr1005" />
                                  <property name="Output List.[1].Column" value="Expr1005" />
                                  <property name="Output List.[1].DataType" value="Int32" />
                                  <property name="Statistics.Open Count" value="1" />
                                  <property name="Statistics.Row Count" value="43" />
                                  <property name="Statistics.Average Row Count" value="43" />
                                  <property name="Defined Values.[0]" value="Expr1005 = Expr1003 + 1" />
                                  <property name="Defined Values.[0].Target" value="Expr1005" />
                                  <property name="Defined Values.[0].DataType" value="Int32" />
                                  <property name="Defined Values.[0].Source" value="Expr1003 + 1" />
                                </properties>
                                <input>
                                  <element operator="TableSpool">
                                    <properties>
                                      <property name="Output List.[0]" value="Expr1003" />
                                      <property name="Output List.[0].Column" value="Expr1003" />
                                      <property name="Output List.[0].DataType" value="Int32" />
                                      <property name="Output List.[1]" value="Expr1004" />
                                      <property name="Output List.[1].Column" value="Expr1004" />
                                      <property name="Output List.[1].DataType" value="Int32" />
                                      <property name="Statistics.Open Count" value="1" />
                                      <property name="Statistics.Row Count" value="43" />
                                      <property name="Statistics.Average Row Count" value="43" />
                                      <property name="Logical Operator" value="Lazy Spool" />
                                      <property name="With Stack" value="True" />
                                    </properties>
                                    <input />
                                  </element>
                                </input>
                              </element>
                              <element operator="Concatenation">
                                <properties>
                                  <property name="Output List.[0]" value="Union1012" />
                                  <property name="Output List.[0].Column" value="Union1012" />
                                  <property name="Output List.[0].DataType" value="Int32" />
                                  <property name="Statistics.Open Count" value="43" />
                                  <property name="Statistics.Row Count" value="42" />
                                  <property name="Statistics.Average Row Count" value="1" />
                                  <property name="Defined Values.Union1012" value="e.EmployeeID; e.EmployeeID; e.EmployeeID" />
                                  <property name="Defined Values.Union1012.[0]" value="e.EmployeeID" />
                                  <property name="Defined Values.Union1012.[0].Table" value="e" />
                                  <property name="Defined Values.Union1012.[0].Column" value="EmployeeID" />
                                  <property name="Defined Values.Union1012.[0].DataType" value="Int32" />
                                  <property name="Defined Values.Union1012.[1]" value="e.EmployeeID" />
                                  <property name="Defined Values.Union1012.[1].Table" value="e" />
                                  <property name="Defined Values.Union1012.[1].Column" value="EmployeeID" />
                                  <property name="Defined Values.Union1012.[1].DataType" value="Int32" />
                                  <property name="Defined Values.Union1012.[2]" value="e.EmployeeID" />
                                  <property name="Defined Values.Union1012.[2].Table" value="e" />
                                  <property name="Defined Values.Union1012.[2].Column" value="EmployeeID" />
                                  <property name="Defined Values.Union1012.[2].DataType" value="Int32" />
                                </properties>
                                <input>
                                  <element operator="IndexSpool">
                                    <properties>
                                      <property name="Output List.[0]" value="e.EmployeeID" />
                                      <property name="Output List.[0].Table" value="e" />
                                      <property name="Output List.[0].Column" value="EmployeeID" />
                                      <property name="Output List.[0].DataType" value="Int32" />
                                      <property name="Statistics.Open Count" value="43" />
                                      <property name="Statistics.Row Count" value="14" />
                                      <property name="Statistics.Average Row Count" value="0" />
                                      <property name="Logical Operator" value="Eager Spool" />
                                      <property name="With Stack" value="False" />
                                      <property name="Index" value="e.ReportsTo" />
                                      <property name="Index.Table" value="e" />
                                      <property name="Index.Column" value="ReportsTo" />
                                      <property name="Index.DataType" value="Int32" />
                                      <property name="Probe" value="Expr1004" />
                                    </properties>
                                    <input>
                                      <element operator="TableScan">
                                        <properties>
                                          <property name="Table" value="Employees AS e" />
                                          <property name="Output List.[0]" value="e.EmployeeID" />
                                          <property name="Output List.[0].Table" value="e" />
                                          <property name="Output List.[0].Column" value="EmployeeID" />
                                          <property name="Output List.[0].DataType" value="Int32" />
                                          <property name="Output List.[1]" value="e.ReportsTo" />
                                          <property name="Output List.[1].Table" value="e" />
                                          <property name="Output List.[1].Column" value="ReportsTo" />
                                          <property name="Output List.[1].DataType" value="Int32" />
                                          <property name="Statistics.Open Count" value="1" />
                                          <property name="Statistics.Row Count" value="9" />
                                          <property name="Statistics.Average Row Count" value="9" />
                                        </properties>
                                        <input />
                                      </element>
                                    </input>
                                  </element>
                                  <element operator="IndexSpool">
                                    <properties>
                                      <property name="Output List.[0]" value="e.EmployeeID" />
                                      <property name="Output List.[0].Table" value="e" />
                                      <property name="Output List.[0].Column" value="EmployeeID" />
                                      <property name="Output List.[0].DataType" value="Int32" />
                                      <property name="Statistics.Open Count" value="43" />
                                      <property name="Statistics.Row Count" value="14" />
                                      <property name="Statistics.Average Row Count" value="0" />
                                      <property name="Logical Operator" value="Eager Spool" />
                                      <property name="With Stack" value="False" />
                                      <property name="Index" value="e.ReportsTo" />
                                      <property name="Index.Table" value="e" />
                                      <property name="Index.Column" value="ReportsTo" />
                                      <property name="Index.DataType" value="Int32" />
                                      <property name="Probe" value="Expr1004" />
                                    </properties>
                                    <input>
                                      <element operator="TableScan">
                                        <properties>
                                          <property name="Table" value="Employees AS e" />
                                          <property name="Output List.[0]" value="e.EmployeeID" />
                                          <property name="Output List.[0].Table" value="e" />
                                          <property name="Output List.[0].Column" value="EmployeeID" />
                                          <property name="Output List.[0].DataType" value="Int32" />
                                          <property name="Output List.[1]" value="e.ReportsTo" />
                                          <property name="Output List.[1].Table" value="e" />
                                          <property name="Output List.[1].Column" value="ReportsTo" />
                                          <property name="Output List.[1].DataType" value="Int32" />
                                          <property name="Statistics.Open Count" value="1" />
                                          <property name="Statistics.Row Count" value="9" />
                                          <property name="Statistics.Average Row Count" value="9" />
                                        </properties>
                                        <input />
                                      </element>
                                    </input>
                                  </element>
                                  <element operator="IndexSpool">
                                    <properties>
                                      <property name="Output List.[0]" value="e.EmployeeID" />
                                      <property name="Output List.[0].Table" value="e" />
                                      <property name="Output List.[0].Column" value="EmployeeID" />
                                      <property name="Output List.[0].DataType" value="Int32" />
                                      <property name="Statistics.Open Count" value="43" />
                                      <property name="Statistics.Row Count" value="14" />
                                      <property name="Statistics.Average Row Count" value="0" />
                                      <property name="Logical Operator" value="Eager Spool" />
                                      <property name="With Stack" value="False" />
                                      <property name="Index" value="e.ReportsTo" />
                                      <property name="Index.Table" value="e" />
                                      <property name="Index.Column" value="ReportsTo" />
                                      <property name="Index.DataType" value="Int32" />
                                      <property name="Probe" value="Expr1004" />
                                    </properties>
                                    <input>
                                      <element operator="TableScan">
                                        <properties>
                                          <property name="Table" value="Employees AS e" />
                                          <property name="Output List.[0]" value="e.EmployeeID" />
                                          <property name="Output List.[0].Table" value="e" />
                                          <property name="Output List.[0].Column" value="EmployeeID" />
                                          <property name="Output List.[0].DataType" value="Int32" />
                                          <property name="Output List.[1]" value="e.ReportsTo" />
                                          <property name="Output List.[1].Table" value="e" />
                                          <property name="Output List.[1].Column" value="ReportsTo" />
                                          <property name="Output List.[1].DataType" value="Int32" />
                                          <property name="Statistics.Open Count" value="1" />
                                          <property name="Statistics.Row Count" value="9" />
                                          <property name="Statistics.Average Row Count" value="9" />
                                        </properties>
                                        <input />
                                      </element>
                                    </input>
                                  </element>
                                </input>
                              </element>
                            </input>
                          </element>
                        </input>
                      </element>
                    </input>
                  </element>
                </input>
              </element>
            </input>
          </element>
        </input>
      </element>
    </executionPlan>
  </expectedPlan>
</test>